#include "rsp_lease.hpp"
#include "../action_constants.hpp"


namespace etcdv3 {

void AsyncLeaseGrantResponse::ParseResponse(LeaseGrantResponse& resp) {
    index = resp.header().revision();
    value.kvs.set_lease(resp.id());
    value.set_ttl(resp.ttl());
    error_message = resp.error();
}

void AsyncLeaseRevokeResponse::ParseResponse(LeaseRevokeResponse& resp) {
    index = resp.header().revision();
}

void AsyncLeaseKeepAliveResponse::ParseResponse(LeaseKeepAliveResponse& resp) {
    index = resp.header().revision();
    value.kvs.set_lease(resp.id());
    value.set_ttl(resp.ttl());
}

void AsyncLeaseTimeToLiveResponse::ParseResponse(LeaseTimeToLiveResponse& resp) {
    index = resp.header().revision();
    value.kvs.set_lease(resp.id());
    value.set_ttl(resp.ttl());

    for (auto& key : resp.keys()) {
        KeyValue kv;
        kv.kvs.mutable_key()->assign(key);
        kv.set_ttl(resp.grantedttl());
        values.push_back(std::move(kv));
    }
}

}

